/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Game;

import IO.models.PlayerConfig;
import Player.Player;
import Player.PlayerInterface;
import Player.Rogue;
import Player.Warrior;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import jcgame.Main;

/**
 *
 * @author insane
 */
public class NewGame {

    private static PlayerInterface player;
    private static String Str;
    private static String StrClass;

    public static boolean StartGame() throws IOException, FileNotFoundException, ClassNotFoundException {
        PlayerConfig.getInstance().load();

        Main.csi.print(0, 0, "enter name hero:");
        Main.csi.locateCaret(0, 1);
        Str = Main.csi.input();

        if (PlayerConfig.getInstance().getPlayer(Str) != null) {
            setPlayer((PlayerInterface) PlayerConfig.getInstance().getPlayer(Str));
            return true;
        } else {
            Main.csi.print(0, 2, "hero " + Str + " no exists");
            Main.csi.print(0, 3, "enter class: 1 - warrior, 2 - rogue");
            Main.csi.locateCaret(0, 4);
            StrClass = Main.csi.input();
            if (Integer.parseInt(StrClass) < 3) {
                switch (Integer.parseInt(StrClass)) {
                    case 1:
                        setPlayer(Warrior.getInstance());
                        break;
                    case 2:
                        setPlayer(Rogue.getInstance());
                        break;
                }
                getPlayer().setName(Str);
                PlayerConfig.getInstance().getPlayers().add((Player) getPlayer());
                return true;
            }
            return false;
        }
    }

    /**
     * @return the player
     */
    public static PlayerInterface getPlayer() {
        return player;
    }

    /**
     * @param aPlayer the player to set
     */
    public static void setPlayer(PlayerInterface aPlayer) {
        player = aPlayer;
    }
}
